<template>
	<view class="p-10">
		<view class="card">
			<u-cell-group>
				<u-cell :title="item.title" :value="options[item.prop]" v-for="(item, index) in data"></u-cell>
				<u-cell title="限期日期" :value="options.requireChangeEndDate" v-if="options.changeType == 0"></u-cell>
				<u-cell title="整改人" :value="options.trueChangeUserName" v-if="options.changeType == 1"></u-cell>
				<u-cell title="整改措施" :value="options.changeInfo" v-if="options.changeType == 1"></u-cell>
				<u-cell title="验收人" :value="options.checkUserName" v-if="options.changeType == 1"></u-cell>
				<up-cell title="现场图片" v-if="options.filePaths?.length">
					<template #value>
						<up-image :show-loading="true" :src="url" width="80px" height="80px"></up-image>
					</template>
				</up-cell>
			</u-cell-group>
			<view class="flex m-t-10">
				<u-button style="width: 200rpx" type="primary" shape="circle" text="批复结果" @click="click2" v-if="approveState == 0"></u-button>
				<u-button style="width: 200rpx" type="primary" shape="circle" text="隐患下达" @click="click" v-if="approveState !== 2"></u-button>
				<u-button style="width: 200rpx" type="primary" shape="circle" text="隐患修改" @click="click1" v-if="approveState !== 2"></u-button>
			</view>
		</view>

		<u-popup :show="show" mode="bottom" @close="show = false" @open="show = true">
			<view class="p-10">
				<view class="card">
					<u-cell-group>
						<u-cell :title="item.title" v-for="(item, index) in formData" :key="index">
							<template #value>{{ options1[item.prop] }}</template>
							<template #label>
								{{ item.label }}
							</template>
						</u-cell>
					</u-cell-group>
				</view>
			</view>
		</u-popup>
	</view>
</template>
<script setup>
import { onLoad } from '@dcloudio/uni-app';
import { ref, unref, nextTick } from 'vue';
import { getNoticeApproveDetail, infoHiddenDanger } from '@/api/hidden-danger.js';
import { apiBaseURL } from '@/config/index.js';

let options = ref({}),
	data = ref([
		{
			title: '检查类型',
			prop: 'dataTypeName'
		},
		{
			title: '检查人',
			prop: 'inspectUserNames'
		},
		{
			title: '日期',
			prop: 'checkDate'
		},
		{
			title: '隐患内容',
			prop: 'hiddenDangerInfo'
		},
		{
			title: '地点',
			prop: 'riskLocationName'
		},
		{
			title: '隐患成因',
			prop: 'hiddenDangerFactorName'
		},
		{
			title: '隐患等级',
			prop: 'hiddenLevelName'
		},
		{
			title: '责任单位',
			prop: 'dutyDeptName'
		},
		{
			title: '责任人',
			prop: 'dutyUserName'
		},
		{
			title: '整改方式',
			prop: 'changeTypeName'
		}
	]);

let url = ref();
let approveState = ref();
onLoad((e) => {
	approveState.value = JSON.parse(e.data)?.approveState;
	infoHiddenDanger({
		id: JSON.parse(e.data)?.id
	}).then((res) => {
		options.value = res.data;
		res.data?.filePaths && res.data.filePaths.length ? (url.value = apiBaseURL + '/rdfile/download/' + res.data.filePaths[0]?.storageUrl) : '';
	});
});
// 隐患下达
const click = () => {
	uni.navigateTo({
		url: '/pages/professional/hiddenTrouble/transmit/assign?id=' + unref(options).id
	});
};
// 隐患修改
const click1 = () => {
	uni.navigateTo({
		url: '/pages/professional/hiddenTrouble/transmit/update?id=' + unref(options).id
	});
};

const show = ref(false);

let formData = ref([
	{
		title: '审批状态',
		prop: 'stateName'
	},
	{
		title: '处理人',
		prop: 'handleUser'
	},
	{
		title: '申请人',
		prop: 'applyUserName'
	},
	{
		title: '申请时间',
		prop: 'applyDate'
	},
	{
		title: '申请原因',
		prop: 'applyInfo'
	},
	{
		title: '受理人',
		prop: 'userName'
	},
	{
		title: '实际审批人',
		prop: 'trueUserName'
	},
	{
		title: '审批意见',
		prop: 'handleInfo'
	}
]);
const options1 = ref({});

function click2() {
	getNoticeApproveDetail({
		id: unref(options).id
	}).then((res) => {
		show.value = true;
		nextTick(() => {
			options1.value = res.data;
		});
	});
}
</script>
<style scoped>
:deep(.u-cell__title) {
	width: 180rpx !important;
}
</style>
